<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */

namespace App\FreeBird\Controllers\Home;

use App\Base\Controllers\Controller;
use App\FreeBird\Contracts\PunchInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;


class PunchController extends Controller
{
    /**
     * 获取分类
     * @return PunchInterface
     */
    public function getPunchInterface()
    {
        return app()->make(PunchInterface::class);
    }

    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function getList(Request $request)
    {
        $where = function ($query) use ($request) {
             $query->where("uid",AUID);  //获取用户
            //时间限制没放
        };
        return $this->getPunchInterface()->getList($where);
    }

    /**
     * 添加
     * @param Request $request
     * @return mixed
     * @throws \App\Base\Exceptions\ApiException
     */
    public function add(Request $request)
    {

        if ($request->getMethod() == 'POST') {
            $validator = Validator::make($request->all(), [
                'strat_title' => 'required',
                'longitude' => 'required',
                'latitude' => 'required',
            ]);
            if ($validator->fails()) {
                $this->throwValidatorException($validator);
            }
            return $this->getPunchInterface()->saveData($request->all());
        }
    }


}